#include <stdio.h>
#include <pthread.h>
#define N 3

int g_idx = 0;
pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;

void* incr(void *arg) {
    usleep(1000);
}

int main(int argc, char *argv[]) {
    int i;
    pthread_t t[N];

    for (i = 0; i < N; ++i) {
        if (pthread_create(&t[i], NULL, incr, NULL) < 0) {
            perror("pthread_create");
        }
    }

    for (i = 0; i < N; ++i) {
        if (pthread_join(&t[i], NULL) < 0) {
            perror("pthread_join");
        }
    }
    
}